<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="Bookmark" href="/favicon.ico">
    <link rel="Shortcut Icon" href="/favicon.ico" />
    <!--[if lt IE 9]>
            <script type="text/javascript" src="lib/html5shiv.js"></script>
            <script type="text/javascript" src="lib/respond.min.js"></script>
            <![endif]-->
    <link rel="stylesheet" type="text/css" href="../static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="../lib/Hui-iconfont/1.0.8/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/style.css" />
    <link rel="stylesheet" href="./../lib/layui/css/layui.css">
    <!--[if IE 6]>
            <script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
            <script>DD_belatedPNG.fix('*');</script>
            <![endif]-->
    <style>
        .sellOut i{
                        display: inline-block;
                        width: 14px;
                        height: 14px;
                        background: url("./../static/img/sellout.svg") no-repeat;background-size:contain;
                        vertical-align: middle;
                        line-height: 14px;
                    }
                </style>
</head>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 商品管理 <span class="c-gray en">&gt;</span>
    商品列表 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);"
        title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
    <div>
        商品名称：
        <input type="text" class="input-text" style="width:150px" placeholder="输入商品名称" id="mobile" name="">
        编号：
        <input type="text" class="input-text" style="width:150px" placeholder="输入商品编号" id="number" name="">
        商品类目：
        <select name="" class="input-text" id="autuStatus" style="width:15%;">
            <option value="">-请选择-</option>
        </select>
        类型：
        <select name="" class="input-text" id="type" style="width:10%;">
            <option value="">-请选择-</option>
            <option value="0">商品</option>
            <option value="1">礼包</option>
            <option value="2">礼品</option>
            <option value="3">热销商品</option>
            <option value="4">抢购商品</option>
        </select>
        状态：
        <select name="" class="input-text" id="status" style="width:10%;">
            <option value="">-请选择-</option>
            <option value="0">下架</option>
            <option value="1">上架</option>
        </select>
        <button type="submit" class="btn btn-success" name="" data-type="reload" id="search"><i class="Hui-iconfont">&#xe665;</i>
            搜索</button>
        <button type="submit" class="btn btn-success " name="" onclick="addCom()"> 添加商品</button>

    </div>
    <table class="layui-hide" id="comList" lay-filter="comList"></table>
    <!-- 加入抢购 -->

    <input type="" name="details_id" id="details_id" value="" style="display:none;" />
    <script type="text/javascript" src="../lib/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="./../static/js/common.js"></script>
    <script type="text/javascript" src="../lib/layer/2.4/layer.js"></script>
    <script type="text/javascript" src="../static/h-ui/js/H-ui.min.js"></script>
    <script type="text/javascript" src="../static/h-ui.admin/js/H-ui.admin.js"></script>
    <script type="text/javascript" src="./../lib/layui/layui.js"></script>
    <script type="text/html" id="titleTpl">
        <a  title="编辑" lay-event="edit" class=""><i class="Hui-iconfont">&#xe6df;</i></a>
        <a  title="删除" lay-event="del" class=""><i class="Hui-iconfont">&#xe6e2;</i></a>
        {{#  if(d.status == true){ }}
        <a  title="下架" lay-event="lowerFrame" class=""><i class="Hui-iconfont">&#xe6de;</i></a>
        {{#  } else { }}
        <a  title="上架" lay-event="shelf" class="" ><i class="Hui-iconfont">&#xe6dc;</i></a>
        {{#  } }}
        {{#  if(d.top == 0){ }}
        <a  title="设置为首页展示" lay-event="setting-home" class=""><i class="Hui-iconfont">&#xe63c;</i></a>
        {{#  } else { }}
        <a  title="取消首页展示" lay-event="home" class=""><i class="Hui-iconfont">&#xe625;</i></a>
        {{#  } }}
        <a  title="加入热销" lay-event="add" class=""><i class="Hui-iconfont">&#xe6c1;</i></a>
        <a  title="加入抢购" lay-event="scare-buying" class=""><i class="Hui-iconfont">&#xe604;</i></a>
        <a  title="设置为奖品" lay-event="prize" class=""><i class="Hui-iconfont">&#xe6bb;</i></a>
        <a  title="设置首页轮播图" lay-event="ad" class=""><i class="Hui-iconfont">&#xe646;</i></a>
</script>
    <script>
        // 页码
        var page = '',
            pages = '';
            var dataTable;
        // 获取分区
        $(function () {
            partitionStatus('autuStatus')
        })
        layui.use('table', function () {
            var table = layui.table;
            dataTable = table.render({
                elem: '#comList',
                cellMinWidth: 80,
                url: admin_url + '/kvmProduct/productList',
                // id为重置表格，进行搜索
                id: 'reload',
                request: {
                    pageName: 'page',
                    limitName: 'size'
                },
                // 传输模式
                // contentType: 'application/json',
                paresData: function (res) {
                    return {
                        'data': res.data
                    }
                },
                response: {
                    statusCode: 200
                },
                // 传入数据
                where: {
                    tokenUserId: userId,
                    token: token
                },
                // 回调
                done: function (res, curr, count) {
                    page = curr;
                    pages = count;
                },
                method: 'post',
                'page': 'true',
                cols: [
                    [{
                            checkbox: true,
                            align: 'center'
                        },
                        {
                            field: 'productNo',
                            title: '编号',
                            align: 'center',
                            width: 125
                        },
                        {
                            field: 'name',
                            title: '商品名称',
                            align: 'center'
                        },
                        {
                            field: 'category',
                            title: '商品分区',
                            align: 'center',
                            templet: function (obj) {
                                var category = '';
                                $.ajax({
                                    type: 'post',
                                    async:false,
                                    xhrFields: {
                                        withCredentials: true
                                    },
                                    url: admin_url +
                                        '/kvmProductPartition/productPartition',
                                    data: {
                                        tokenUserId: userId,
                                        token: token,
                                        id:obj.category

                                    },
                                    success: function (data) {
                                        if(data.code == 200 && data.data != null){
                                        return category ='<span>' +  data.data.name + '</span>'
                                        }else {
                                            return category ='<span></span>'
                                        }
                                    }
                                })
                                return category
                            }
                        },
                        {
                            field: 'remark',
                            title: '商品描述',
                            align: 'center'
                        },
                        {
                            field: 'createTime',
                            title: '商品添加时间',
                            align: 'center',
                            templet: function (obj) {
                                return '<span title="' + obj.createTime + '">' + obj.createTime +
                                    '</span>'
                            }
                        },
                        {
                            field: 'price',
                            title: '商品价格',
                            align: 'center'
                        },
                        {
                            field: 'discount',
                            title: '礼包折扣',
                            align: 'center',
                            templet:function(obj){
                                if(obj.discount == null){
                                    return '<span></span>'
                                }else{
                                    return '<span>' + obj.discount + '</span>'
                                }
                            }
                        },
                        {
                            field: 'currentStock',
                            title: '库存',
                            align: 'center',
                            templet:function(obj){
                                if(obj.currentStock == 0){
                                    return '<span style = "color:#ff0000">售罄</span>'
                                }else if(obj.currentStock == null){
                                    return '<span></span>'
                                }
                                else{
                                    return '<span>' + obj.currentStock + '</span>'
                                }
                            }
                        },
                        {
                            field: 'type',
                            title: '商品类型',
                            align: 'center',
                            templet:function(obj){
                                if(obj.type == 0){
                                    return '<span  class="layui-badge layui-bg-green">商品</span>'
                                }else if(obj.type == 1){
                                    return '<span  class="layui-badge layui-bg-cyan">礼包</span>'
                                }else if(obj.type == 2){
                                    return '<span  class="layui-badge layui-bg-orange">礼品</span>'
                                }else if(obj.type == 3){
                                    return '<span  class="layui-badge">热销商品</span>'
                                }else if(obj.type == 4){
                                    return '<span  class="layui-badge layui-bg-blue">抢购商品</span>'
                                }else if(obj.type == 5){
                                    return '<span  class="layui-badge layui-bg-gray">特色商品</span>'
                                }else if(obj.type == 6){
                                    return '<span  class="layui-badge layui-bg-black">奖品</span>'
                                }else{
                                    return '<span></span>'
                                }
                            }
                        },
                        {
                            field: 'status',
                            title: '状态',
                            align: 'center',
                            templet: function (obj) {
                                if (obj.status == 0) {
                                    return '<span  class="layui-badge">下架</span>'
                                } else if (obj.status == 1) {
                                    return '<span  class="layui-badge layui-bg-green">上架</span>'
                                }else{
                                    return '<span></span>'
                                }
                            }
                        },
                        {
                            toolbar: '#titleTpl',
                            title: '操作',
                            align: 'center',
                            width: 230
                        }
                    ]
                ]
            })
            // 搜索功能
            $('#search').on('click', function () {
                var name = $("#mobile").val(),
                category = $("#autuStatus option:selected").val(),
                    productNo = $("#number").val(),
                    status = $("#status option:selected").val(),
                    type = $("#type option:selected").val();
                    dataTable.reload({
                    where: {
                        "token": token,
                        "tokenUserId": userId,
                        "name": name,
                        "productNo": productNo,
                        'status': status,
                        'category':category,
                        'type':type
                    }, page: {
                        curr: 1
                    }
                });
            });
            table.on('tool(comList)', function (obj) {
                var data = obj.data;
                var id = data.id;
                if (obj.event === 'edit') {
                    var index = layer.open({
                        type: 2,
                        title: '编辑商品',
                        id: id,
                        content: './comList-edit.html'
                    })
                    layer.full(index);
                    $("#details_id").val(id)
                } else if (obj.event === 'setting-home') {
                        layer.confirm('是否设置为首页展示', { title: '设置首页展示' }, function () {
                            $.ajax({
                                type:'post',
                                xhrFields:{withCredentials:true},
                                url:admin_url + '/kvmProduct/productHomePageShow',
                                data:{tokenUserId: userId, token: token, id:id},
                                success:function(data){
                                    if (data.code == 200) {
									layer.msg('设置成功', {
										time: 1000,
										end: function () {
                                            $(".layui-laypage-btn").click();
										}
									})
								} else {
									layer.msg(data.msg, {
										time: 1500
									})
								}
                                },error:function(data){
                                    layer.msg(data.msg)
                                }
                            })
                        })
                }else if(obj.event == 'characteristic'){
                    layer.confirm("是否设置为特色商品",{title:'添加特色商品'},function(){
                        $.ajax({
                                type:'post',
                                xhrFields:{withCredentials:true},
                                url:admin_url + '/kvmProduct/setFeaturesProduct',
                                data:{tokenUserId: userId, token: token, id:id},
                                success:function(data){
                                    if (data.code == 200) {
									layer.msg('设置成功', {
										time: 1000,
										end: function () {
                                            $(".layui-laypage-btn").click();
										}
									})
								} else {
									layer.msg(data.msg, {
										time: 1500
									})
								}
                                },error:function(data){
                                    layer.msg(data.msg)
                                }
                            })
                    })
                }else if(obj.event == 'delCharacteristic'){
                    layer.confirm("是否取消特色商品",{title:'取消特色商品'},function(){
                        $.ajax({
                                type:'post',
                                xhrFields:{withCredentials:true},
                                url:admin_url + '/kvmProduct/cancelFeaturesProduct',
                                data:{tokenUserId: userId, token: token, id:id},
                                success:function(data){
                                    if (data.code == 200) {
									layer.msg('取消成功', {
										time: 1000,
										end: function () {
                                            $(".layui-laypage-btn").click();
										}
									})
								} else {
									layer.msg(data.msg, {
										time: 1500
									})
								}
                                },error:function(data){
                                    layer.msg(data.msg)
                                }
                            })
                    })
                }
                 else if (obj.event === 'home') {
                        layer.confirm('是否取消首页展示', { title: '取消首页展示' }, function () {
                            $.ajax({
                                type:'post',
                                xhrFields:{withCredentials:true},
                                url:admin_url + '/kvmProduct/productHomePageHide',
                                data:{tokenUserId: userId, token: token, id:id},
                                success:function(data){
                                    if (data.code == 200) {
									layer.msg('取消成功', {
										time: 1000,
										end: function () {
										  $(".layui-laypage-btn").click();
										}
									})
								} else {
									layer.msg(data.msg, {
										time: 1500
									})
								}
                                },error:function(data){
                                    layer.msg(data.msg)
                                }
                            })
                        })
                } else if (obj.event === 'del') {
                    layer.confirm('是否删除该商品', function () {
                        $.ajax({
                            type: "post",
                            xhrFields: {
                                withCredentials: true
                            },
                            url: admin_url + '/kvmProduct/delProduct',
                            data: {
                                tokenUserId: userId,
                                token: token,
                                id: id
                            },
                            success: function (data) {
                                if (data.code == 200) {
                                    layer.msg('删除成功', {
                                        time: 1000,
                                        end: function () {
                                            // location.replace(location.href)
                                            $(".layui-laypage-btn").click();
                                            
                                        }
                                    })
                                } else {
                                    layer.msg(data.msg)
                                }
                            }
                        })
                    })
                } else if (obj.event === 'lowerFrame') {
                    layer.confirm('是否下架该商品', function () {
                        $.ajax({
                            type: "post",
                            xhrFields: {
                                withCredentials: true
                            },
                            url: admin_url + '/kvmProduct/productSoldOut',
                            data: {
                                tokenUserId: userId,
                                token: token,
                                id: id
                            },
                            success: function (data) {
                                if (data.code == 200) {
                                    layer.msg('已成功下架', {
                                        end: function () {
                                            time: 1000,
                                            $(".layui-laypage-btn").click();
                                        }
                                    })
                                } else {
                                    layer.msg(data.msg)
                                }
                            }
                        })
                    })
                } else if (obj.event === 'add') {
                    var index = layer.open({
                        type: 2,
                        title: '加入热销专区',
                        id:id ,
                        content: './add-hotSale.html'
                    })
                    layer.full(index);
                    $("#details_id").val(id)
                } else if (obj.event === 'shelf') {
                    layer.confirm('是否上架该商品', function () {
                        $.ajax({
                            type: "post",
                            xhrFields: {
                                withCredentials: true
                            },
                            url: admin_url + '/kvmProduct/productPutaway',
                            data: {
                                tokenUserId: userId,
                                token: token,
                                id: id
                            },
                            success: function (data) {
                                if (data.code == 200) {
                                    layer.msg('上架成功', {
                                        end: function () {
                                            // 重载当前行
                                            $(".layui-laypage-btn").click();
                                        }
                                    })
                                } else {
                                    layer.msg(data.msg)
                                }
                            }
                        })
                    })
                }else if (obj.event === 'prize') {
                    layer.confirm('是否设置为奖品', {
                        title: '设置奖品'
                    }, function () {
                        $.ajax({
                            type: "post",
                            xhrFields: {
                                withCredentials: true
                            },
                            url: admin_url + '/kvmProduct/product2GiftSpace',
                            data: {
                                tokenUserId: userId,
                                token: token,
                                productId: id
                            },
                            success: function (data) {
                                if (data.code == 200) {
                                    layer.msg('设置成功', {
                                        time: 1000,
                                        end: function () {
                                            $(".layui-laypage-btn").click();
                                        }
                                    })
                                } else {
                                    layer.msg(data.msg)
                                }
                            }
                        })
                    })
                } else if (obj.event === 'ad') {
                    $.ajax({
                            type: "post",
                            xhrFields: {
                                withCredentials: true
                            },
                            url: admin_url + '/kvmRoll/rollByproductId',
                            data: {
                                tokenUserId: userId,
                                token: token,
                                prodcutId: id
                            },
                            success: function (data) {
                                var status = '';
                                setTimeout(function(){
                                    if(data.data != null && data.code == 200){
                                        $("#cStatus").val(data.data.status)
                                        $("#tips").hide(0);
                                      
                                    }else{
                                    }
                                },0)
                                layer.confirm(
                        '<div style="width:360px"><div class="row cl" style="margin-bottom:10px;">' +
                        '<label style = "display:inline-block;width:120px;text-align:right" >状态：</label><select style="width:150px" id = "cStatus" class="input-text" >' +
                        '<option value = "0">关闭</option>' +
                        '<option value = "1">显示</option>' +
                        '</select>' +
                        '</div><div class="row cl"><label style = "display:inline-block;width:120px;text-align:right" >排序：</label><input id="sort" style="width:150px"  class="input-text" type="text" placeholder="请输入排序数"></div><div class = "" style = "text-align:center;margin-top:10px;" id = "tips"><span style = "color:#ff0000;">商品还未设置轮播</span></div></div>', {
                            title: '设置首页轮播'
                        },
                        function () {
                            var cStatus = $("#cStatus option:selected").val(),
                                sort = $("#sort").val();
                            $.ajax({
                                type: "post",
                                xhrFields: {
                                    withCredentials: true
                                },
                                url: admin_url + '/kvmRoll/addRoll',
                                data: {
                                    tokenUserId: userId,
                                    token: token,
                                    sort: sort,
                                    status: cStatus,
                                    productId: id
                                },
                                success: function (data) {
                                    if (data.code == 200) {
                                        layer.msg('设置成功', {
                                            time: 1000,
                                            end: function () {
                                                $(".layui-laypage-btn").click();
                                            }
                                        })
                                    } else {
                                        layer.msg(data.msg)
                                    }
                                }
                            })
                        })
                            }
                        })

                } else if (obj.event === 'scare-buying') {
                    var index = layer.open({
                        type: 2,
                        title: '加入抢购专区',
                        id: id,
                        content: './scare-buying-add.html'
                    })
                    layer.full(index);
                    $("#details_id").val(id)
                }
            })
        })

        function addCom() {
            var index = layer.open({
                type: 2,
                title: '添加商品',
                content: './addCom.html'
            })
            layer.full(index);
        }
    </script>
</div>

<body>

</body>

</html>